package com.demo.rxjavademo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/1/3.
 */

public class DateUtils {
    public static String FriendlyDate(String compareDate) {
        int dayDiff = 0;
        String strCompare = null;
        Date dateToday = new Date(System.currentTimeMillis());
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        try {
            Date dateCompare = format.parse(compareDate);
            dayDiff = (int) ((dateToday.getTime() - dateCompare.getTime()) / (1000 * 3600 * 24));
            strCompare = new SimpleDateFormat("MM月dd日").format(dateCompare);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        if (dayDiff <= 0)
            return "今日热文";
        else if (dayDiff == 1)
            return "昨日";
        else if (dayDiff == 2)
            return "前日";
        else
            return strCompare;

    }
}
